package com.test.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.test.util.TaoBaoUtil;

/**
 * 得到回调地址中的信息
 * @author liuxl
 *
 */
public class GetInfoServlet extends HttpServlet {
	protected final Log log = LogFactory.getLog(GetInfoServlet.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req,resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		log.error("get taobao sessionKey start...... ");
		//得到sessionKey
		String topSession = req.getParameter("top_session");
		log.error("topSession==:::"+topSession);
		//得到nick
		String topParameters = req.getParameter("top_parameters");
		log.error("topParameters===:::"+topParameters);
		String nick = TaoBaoUtil.ParametersName(topParameters);
		//把sessionKey和nick写到session中，并设置session的有效期为100分钟
		req.getSession().setAttribute("sessionKey", topSession);
		req.getSession().setAttribute("nick", nick);
		req.getSession().setMaxInactiveInterval(6000);
		//转到获得商品的iid页面
		//req.getRequestDispatcher("/operation/getIid.jsp").forward(req, resp);
	}
	

}
